package nah;

import robocode.HitByBulletEvent;
import robocode.HitRobotEvent;
import robocode.HitWallEvent;
import robocode.Robot;
import robocode.ScannedRobotEvent;
import java.awt.Color;

/**
 * Implements the KillaRobot, a robot that will destroy everything it sees. This
 * robot will move in a straight line firing at its enemies whenever they are scanned by the radar.
 * If the robot runs into a wall, it will turn right 90 degrees and move forward again. If hit by
 * the enemy robot, it will face the enemy robot and ram the enemy back and fire at max power. If
 * hit by a bullet, it will change its direction by turning right 90 degrees and moving foward an
 * extra 50 pixels.
 * 
 * @author Nathaniel Ashe
 * 
 */
public class KillaRobot extends Robot {

  /**
   * The <code>run()</code> starts the "KillaRobot" movements.
   */
  public void run() {
    setColors(Color.red, Color.black, Color.black, Color.green, null);
    while (true) {
      ahead(50);
      turnGunRight(360);
    }
  }

  /**
   * When enemy is scanned, the robot will fire at full power.
   * 
   * @Override overrides onScannedRobot to do these procedures.
   * @param event Provides information about the scanned enemy robot.
   */
  @Override
  public void onScannedRobot(ScannedRobotEvent event) {
    if (event.getDistance() < 150) {
      turnRight(event.getBearing());
      fire(3);
      ahead(100);
    }
    else {
      fire(3);
    }
  }

  /**
   * When the robot hits the wall, it will turn right 90 degrees.
   * 
   * @Override overrides onScannedRobot to do these procedures.
   * @param event Provides information about the scanned enemy robot.
   */
  @Override
  public void onHitWall(HitWallEvent event) {
    turnRight(90);
  }

  /**
   * When hit by another robot, it will turn towards the enemy robot and ram back.
   * 
   * @Override overrides onScannedRobot to do these procedures.
   * @param event Provides information about the scanned enemy robot.
   */
  @Override
  public void onHitRobot(HitRobotEvent event) {
    turnRight(event.getBearing());
    fire(3);
    ahead(100);

  }

  /**
   * When hit by a bullet, the robot will turn right and move forward an additional 50 pixels.
   * 
   * @Override overrides onScannedRobot to do these procedures.
   * @param event Provides information about the scanned enemy robot.
   */
  @Override
  public void onHitByBullet(HitByBulletEvent event) {
    turnRight(90);
    ahead(50);
  }
}
